package com.dzxcqmxm.servlet.xt;

import com.dzxcqmxm.Dao.XtDao;
import com.dzxcqmxm.Dao.impl.XtDaoImpl;
import com.dzxcqmxm.JB.Xt;
import com.dzxcqmxm.Dao.impl.testDel.deleteAllFile;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Payboi
 * @create 2022/6/4-21:33
 * @FileName delXTXCServlet
 * @Description
 */
@WebServlet("/delXTXCServlet")
public class delXTXCServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        /**
         * 这是删除数据库数据
         */
        XtDao xtDao = new XtDaoImpl();
        Xt xt = new Xt();
        try {
            //获得表单数据
            xt.setXTXCName(new String(request.getParameter("delXT" ).getBytes("iso-8859-1"),"UTF-8"));


            try {
                xtDao.delXTXC(xt.getXTXCName());
            } catch (Exception e) {
                e.printStackTrace();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        /**
         * 把本机文件夹也删掉,得获取路径
         */
        String dir = "D:/电子相册/"+xt.getXTXCName();
        deleteAllFile.deleteAllFile(dir);

        response.sendRedirect("/dzxc/admin/XiangCheFenLei.jsp");

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }
}
